/*
** Copyright (C) 2010 Calin Radoni
**
** This file is part of CHScanner.
**
** CHScanner is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** CHScanner is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with CHScanner. If not, see <http://www.gnu.org/licenses/>.
*/

#include "StdAfx.h"
#include "PacketBuilderPromisc.h"

//---------------------------------------------------------------------------

PacketBuilderPromisc::PacketBuilderPromisc(void) : PacketBuilder()
{
}

PacketBuilderPromisc::~PacketBuilderPromisc(void)
{
}

//---------------------------------------------------------------------------

bool PacketBuilderPromisc::BuildPacketPromiscBcast47(BYTE srcMacIn[6], BYTE srcIpIn[4], BYTE dstIpIn[4])
{
	BYTE dstMAC[6];

	dstMAC[0] = 0xFF;
	dstMAC[1] = 0xFF;
	dstMAC[2] = 0xFF;
	dstMAC[3] = 0xFF;
	dstMAC[4] = 0xFF;
	dstMAC[5] = 0xFE;

	return BuildPacketARP(1, srcMacIn, srcMacIn, srcIpIn, dstMAC, eth00, dstIpIn);
}

bool PacketBuilderPromisc::BuildPacketPromiscBcast16(BYTE srcMacIn[6], BYTE srcIpIn[4], BYTE dstIpIn[4])
{
	BYTE dstMAC[6];

	dstMAC[0] = 0xFF;
	dstMAC[1] = 0xFF;
	dstMAC[2] = 0x00;
	dstMAC[3] = 0x00;
	dstMAC[4] = 0x00;
	dstMAC[5] = 0x00;

	return BuildPacketARP(1, srcMacIn, srcMacIn, srcIpIn, dstMAC, eth00, dstIpIn);
}

bool PacketBuilderPromisc::BuildPacketPromiscBcast8(BYTE srcMacIn[6], BYTE srcIpIn[4], BYTE dstIpIn[4])
{
	BYTE dstMAC[6];

	dstMAC[0] = 0xFF;
	dstMAC[1] = 0x00;
	dstMAC[2] = 0x00;
	dstMAC[3] = 0x00;
	dstMAC[4] = 0x00;
	dstMAC[5] = 0x00;

	return BuildPacketARP(1, srcMacIn, srcMacIn, srcIpIn, dstMAC, eth00, dstIpIn);
}

bool PacketBuilderPromisc::BuildPacketPromiscGroup(BYTE srcMacIn[6], BYTE srcIpIn[4], BYTE dstIpIn[4])
{
	BYTE dstMAC[6];

	dstMAC[0] = 0x01;
	dstMAC[1] = 0x00;
	dstMAC[2] = 0x00;
	dstMAC[3] = 0x00;
	dstMAC[4] = 0x00;
	dstMAC[5] = 0x00;

	return BuildPacketARP(1, srcMacIn, srcMacIn, srcIpIn, dstMAC, eth00, dstIpIn);
}

bool PacketBuilderPromisc::BuildPacketPromiscMcast0(BYTE srcMacIn[6], BYTE srcIpIn[4], BYTE dstIpIn[4])
{
	BYTE dstMAC[6];

	dstMAC[0] = 0x01;
	dstMAC[1] = 0x00;
	dstMAC[2] = 0x5E;
	dstMAC[3] = 0x00;
	dstMAC[4] = 0x00;
	dstMAC[5] = 0x00;

	return BuildPacketARP(1, srcMacIn, srcMacIn, srcIpIn, dstMAC, eth00, dstIpIn);
}

bool PacketBuilderPromisc::BuildPacketPromiscMcast1(BYTE srcMacIn[6], BYTE srcIpIn[4], BYTE dstIpIn[4])
{
	BYTE dstMAC[6];

	dstMAC[0] = 0x01;
	dstMAC[1] = 0x00;
	dstMAC[2] = 0x5E;
	dstMAC[3] = 0x00;
	dstMAC[4] = 0x00;
	dstMAC[5] = 0x01;

	return BuildPacketARP(1, srcMacIn, srcMacIn, srcIpIn, dstMAC, eth00, dstIpIn);
}

//---------------------------------------------------------------------------

bool PacketBuilderPromisc::BuildPacketPromisc(PromiscPacketType type, BYTE srcMacIn[6],  BYTE srcIpIn[4], BYTE dstIpIn[4])
{
	switch(type){
		case __pptBcast47 :
			return BuildPacketPromiscBcast47(srcMacIn, srcIpIn, dstIpIn);

		case __pptBcast16 :
			return BuildPacketPromiscBcast16(srcMacIn, srcIpIn, dstIpIn);

		case __pptBcast8 :
			return BuildPacketPromiscBcast8(srcMacIn, srcIpIn, dstIpIn);

		case __pptGroup :
			return BuildPacketPromiscGroup(srcMacIn, srcIpIn, dstIpIn);

		case __pptMcast0 :
			return BuildPacketPromiscMcast0(srcMacIn, srcIpIn, dstIpIn);

		case __pptMcast1 :
			return BuildPacketPromiscMcast1(srcMacIn, srcIpIn, dstIpIn);

		default:
			return false;
	}
}

//---------------------------------------------------------------------------
